/*
 * Copyright (c) 2015 SeNDA
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
#include "./info.h"
#include <map>
#include <string>

CInfo::CInfo() :
  CPU(0), MEM(0), name(""), user("") {
  cpuV = std::map<int, float>();
  memV = std::map<int, float>();
}

CInfo::CInfo(float cpu, float mem, std::string nName, std::string nUser) :
  CPU(cpu), MEM(mem), name(nName), user(nUser) {
  cpuV = std::map<int, float>();
  memV = std::map<int, float>();
}

CInfo::~CInfo() {
  cpuV.clear();
  memV.clear();
}

void CInfo::addCPU(int at, float ncpu) {
  CPU += ncpu;
  cpuV[at] = ncpu;
}

void CInfo::addMEM(int at, float nmem) {
  MEM += nmem;
  memV[at] = nmem;
}

float CInfo::getCPUat(int t) {
  if (cpuV.find(t) != cpuV.end())
    return cpuV[t];
  else
    return 0;
}

float CInfo::getMEMat(int t) {
  if (memV.find(t) != memV.end())
    return memV[t];
  else
    return 0;
}
